<template>
    <div class>
      <el-form :model="ruleForm" inline ref="ruleForm" label-width="140px" size="mini">
        <my-form-item
          v-for="item in list"
          :label="item.fieldLabel"
          :key="item.fieldName"
          v-show="item.fieldType=='text'"
        >
          <el-input  v-model="ruleForm[item.fieldName]"></el-input>
        </my-form-item>
      </el-form>
    </div>
  </template>
  
  <script>
  export default {
    components: {},
    props: {
      registerId: {
        type: String,
        default: ""
      },
      type:{
        type: String,
        default: ""
      }
  
    },
    data() {
      return {
        ruleForm: {},
        list: []
      };
    },
    computed: {},
    mounted() {
      this.init();
    },
    methods: {
      init() {
        if(this.type=='add' || this.list.length==0){
          let params = {
            registerId: this.registerId
          };
          this.$api
            .formPost(
              "/api/biz/components/componentProperties/doGetByRegisterIdAndStatus",
              params
            )
            .then(res => {
              if (res.retHead.code == "0000000") {
                this.list = res.retBody;
              }
            });
        }
      },
      doSave(id, path, name) {
        // console.log(this.list);
        let params = {
          applicationPath: path,
          componentName: name,
          componentKey: id,
          formInfo: this.ruleForm,
          propertiesInfo:this.list,
        };
        let that = this;
        return new Promise((resolve, reject) => {
          that.$api
            .post("/api/biz/components/componentTableInfo/doSaveJson", params)
            .then(res => {
              if (res.retHead.code == "0000000") {
                resolve(res.retBody);
              } else {
                that.$message.error(res.retHead.message);
              }
            });
        });
      },
      getData(entId) {
        this.$api
          .formPost(
            "/api/biz/components/componentTableInfo/selectByComponentKey",
            {
              componentKey: entId
            }
          )
          .then(res => {
            if (res.retHead.code == "0000000") {
              if(res.retBody && res.retBody.propertiesInfo){
                this.list=JSON.parse(res.retBody.propertiesInfo);
              }
              if(res.retBody && res.retBody.formInfo){
                this.ruleForm = JSON.parse(res.retBody.formInfo);
              }
             
            } else {
              this.$message({
                type: "error",
                message: res.retHead.message
              });
            }
          });
      }
    }
  };
  </script>
  <style lang='scss' scoped>
  </style>